package com.action.Interceptor;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.action.interfaces.ActionConstants;
import com.entity.Users;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class AuthorityInterceptor extends MethodFilterInterceptor{

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		String servletPath = request.getServletPath();
		
		Users user = (Users) session.getAttribute("user");
		
		if(user != null) {
//			/**
//			 * 鉴权
//			 */
//			Map<String, String> urlMap = (Map<String, String>) session.getAttribute("urlMap");
//			boolean noFilter1 = servletPath.startsWith("/pages/error/");
//			boolean noFilter2 = servletPath.startsWith("/User_login");
//			boolean noFilter3 = servletPath.startsWith("/User_logout");
//			if(!noFilter1 && !noFilter2 && !noFilter3 && urlMap != null && !urlMap.containsValue(servletPath)){
//				return ActionConstants.ACCESS_DENY;
//			}
			
			return invocation.invoke();
		} else {
			return Action.LOGIN;
		}
	}


}
